package com.ruoyi.utils;

import com.ruoyi.enums.OrderStatusEnum;

/**
 * 订单工具类
 */
public class OrderUtils {

    /**
     * 更改订单状态
     * @param orderStatus
     * @param operate
     * @return
     */
    public static String chgStatus(String orderStatus, String operate){
        OrderStatusEnum orderStatusEnum = getOrderStatusEnumByType(orderStatus);
        if (orderStatusEnum == null) {
            throw new IllegalArgumentException("Unknown order status: " + orderStatus);
        }
        String status = "";
        switch (orderStatusEnum){
            case NOTPAY:
                if (operate.equals("付款")){
                    status =  "2";
                }
                break;
            case SUCCESS:
                if (operate.equals("发货")){
                    status =  "3";
                } else if (operate.equals("退款")){
                    status =  "5";
                }
                break;
            case Send_Goods:
                if (operate.equals("确认收货")) {
                    status = "4";
                }
                break;
            case Receive_Goods:
                if (operate.equals("退款")) {
                    status = "5";
                } else if (operate.equals("退换货")) {
                    status = "7";
                }
                break;
            case REFUND_PROCESSING:
                if (operate.equals("同意退款")) {
                    status = "6";
                } else if (operate.equals("不同意退款")) {
                    status = "8";
                }
                break;
            case REFUND_SUCCESS:
                break;
            case GOODS_CHANGE:
                if (operate.equals("同意退换货")) {
                    status = "7";
                } else if (operate.equals("不同意退换货")) {
                    status = "8";
                }
                break;
            case ORDER_OVER:
                break;
            default:
                throw new IllegalArgumentException("Unknown order status: " + orderStatus);
        }
        return status;
    }

    /**
     * 根据订单类型获取订单号
     * @param mode
     * @return
     */
    public static String genOrdersNo(String mode){
        String orderNo = "";
        if (mode.equals("D")){
            //设备订单
            orderNo =  "DNO"+ UUIDUtils.orderNo();
        }else if (mode.equals("C")){
            //内容订单
            orderNo =  "CNO"+ UUIDUtils.orderNo();
        }else if (mode.equals("S")){
            //内容订单
            orderNo =  "SNO"+ UUIDUtils.orderNo();
        }
        return orderNo;
    }

    /**
     * 根据订单类型获取订单号
     * @param mode
     * @return
     */
    public static String getRefundNo(String mode){
        String orderNo = "";
        if (mode.equals("D")){
            //设备订单
            orderNo =  "REFUND_DNO"+ UUIDUtils.orderNo();
        }else if (mode.equals("C")){
            //内容订单
            orderNo =  "REFUND_CNO"+ UUIDUtils.orderNo();
        }
        return orderNo;
    }

    /**
     * 根据类型值获取订单状态枚举
     * @param type
     * @return
     */
    private static OrderStatusEnum getOrderStatusEnumByType(String type) {
        for (OrderStatusEnum statusEnum : OrderStatusEnum.values()) {
            if (statusEnum.getType().equals(type)) {
                return statusEnum;
            }
        }
        return null;
    }

}
